package com.rongzhe.house.login.controller;

import com.rongzhe.house.common.resp.ApiResult;
import com.rongzhe.house.login.entity.User;
import com.rongzhe.house.login.service.LoginService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 找回账户信息
 * @author Chengjia
 * @date 2018/3/15 15:11
 */
@Controller
@RequestMapping("/findccount")
public class FindController {
    @Autowired
    private LoginService loginService;

    //1 验证的身份是否注册了 或者是否合法 下发短信验证正确信
    @RequestMapping("/validate/phone")
    @ResponseBody
    public ApiResult validateMobile(User user){
       return loginService.validatePhone(user);
    }

    @RequestMapping("/validate/code")
    @ResponseBody
    public ApiResult validateCode(HttpServletRequest request, String mobile, String imgId, String imgVValue){
        return loginService.validateCode(mobile,imgId,imgVValue,request);
    }

    @RequestMapping("/doNextStep")
    @ResponseBody
    public ApiResult doNextStep(User user,String vcode){
        return loginService.validateFindPhoneCode(user,vcode);
    }

    //2 设置新密码
    @RequestMapping("/doEdit")
    @ResponseBody
    public ApiResult doEdit(User user){
        return loginService.updatePwd(user);
    }
    //3 成功


    @RequestMapping("/index")
    public String find(){
        return "back_pw_check";
    }
    @RequestMapping("/index/reset")
    public String reset(Model model,User user){
        //检验是否需要找回密码
        if(null!=user&& !StringUtils.isBlank(user.getMobile())&&user.getId()!=0){
            model.addAttribute("cu",user);
        }
        return "back_pw_reset";
    }
    @RequestMapping("/ok")
    public String ok(){
        return "back_pw_ok";
    }
}
